using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the PromoProductCrossSellMap class.
	/// </summary>
	[Serializable]
	public partial class PromoProductCrossSellMapCollection : ActiveList<PromoProductCrossSellMap,PromoProductCrossSellMapCollection> 
	{	   
		public PromoProductCrossSellMapCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Promo_Product_CrossSell_Map table.
	/// </summary>
	[Serializable]
	public partial class PromoProductCrossSellMap : ActiveRecord<PromoProductCrossSellMap>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public PromoProductCrossSellMap()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public PromoProductCrossSellMap(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public PromoProductCrossSellMap(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public PromoProductCrossSellMap(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Promo_Product_CrossSell_Map", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarProductID = new TableSchema.TableColumn(schema);
				colvarProductID.ColumnName = "productID";
				colvarProductID.DataType = DbType.Int32;
				colvarProductID.MaxLength = 0;
				colvarProductID.AutoIncrement = false;
				colvarProductID.IsNullable = false;
				colvarProductID.IsPrimaryKey = true;
				colvarProductID.IsForeignKey = true;
				colvarProductID.IsReadOnly = false;
				colvarProductID.DefaultSetting = @"";
				
					colvarProductID.ForeignKeyTableName = "CSK_Store_Product";
				schema.Columns.Add(colvarProductID);
				
				TableSchema.TableColumn colvarCrossProductID = new TableSchema.TableColumn(schema);
				colvarCrossProductID.ColumnName = "crossProductID";
				colvarCrossProductID.DataType = DbType.Int32;
				colvarCrossProductID.MaxLength = 0;
				colvarCrossProductID.AutoIncrement = false;
				colvarCrossProductID.IsNullable = false;
				colvarCrossProductID.IsPrimaryKey = true;
				colvarCrossProductID.IsForeignKey = true;
				colvarCrossProductID.IsReadOnly = false;
				colvarCrossProductID.DefaultSetting = @"";
				
					colvarCrossProductID.ForeignKeyTableName = "CSK_Store_Product";
				schema.Columns.Add(colvarCrossProductID);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Promo_Product_CrossSell_Map",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ProductID")]
		public int ProductID 
		{
			get { return GetColumnValue<int>(Columns.ProductID); }

			set { SetColumnValue(Columns.ProductID, value); }

		}

		  
		[XmlAttribute("CrossProductID")]
		public int CrossProductID 
		{
			get { return GetColumnValue<int>(Columns.CrossProductID); }

			set { SetColumnValue(Columns.CrossProductID, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Product ActiveRecord object related to this PromoProductCrossSellMap
		/// 
		/// </summary>
		public Commerce.Common.Product Product
		{
			get { return Commerce.Common.Product.FetchByID(this.ProductID); }

			set { SetColumnValue("productID", value.ProductID); }

		}

		
		
		/// <summary>
		/// Returns a Product ActiveRecord object related to this PromoProductCrossSellMap
		/// 
		/// </summary>
		public Commerce.Common.Product ProductToCrossProductID
		{
			get { return Commerce.Common.Product.FetchByID(this.CrossProductID); }

			set { SetColumnValue("crossProductID", value.ProductID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varProductID,int varCrossProductID)
		{
			PromoProductCrossSellMap item = new PromoProductCrossSellMap();
			
			item.ProductID = varProductID;
			
			item.CrossProductID = varCrossProductID;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varProductID,int varCrossProductID)
		{
			PromoProductCrossSellMap item = new PromoProductCrossSellMap();
			
				item.ProductID = varProductID;
			
				item.CrossProductID = varCrossProductID;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ProductIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn CrossProductIDColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ProductID = @"productID";
			 public static string CrossProductID = @"crossProductID";
						
		}

		#endregion
		
		
		
	}

}

